package leetcode.editor.Interview;

import java.util.Scanner;

public class Main1_1 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        while (scanner.hasNext()){
            int num = scanner.nextInt();
            int a= num /3;
            int b= num %3;
            int res=0,sum=0;
            while (a>=3){
                res += a;
                sum += b;

                a = a /3;
                b = a %3;
            }
            sum = sum + b;
            while(sum >=3){
                sum = sum /3;
                b = sum %3;


            }
        }
    }
}
